package com.example.navigation.components

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Map
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.vector.ImageVector

/**
 * Created with IntelliJ IDEA.
 * @Author: Liao Run
 * @Date: 2024-06-13 9:57
 * @Description:
 **/
@Composable
fun MyBottomAppBar(itemClick: (index: Int) -> Unit) {
    val list = listOf(
        BottomItem("map", "地图", Icons.Filled.Map),
        BottomItem("my", "我", Icons.Filled.AccountBox)
    )

    var currentIndex by remember {
        mutableIntStateOf(0)
    }

    NavigationBar {
        list.mapIndexed { index, it ->
            NavigationBarItem(selected = currentIndex == index, onClick = {
                currentIndex = index
                itemClick(index)
            }, icon = {
                Icon(imageVector = it.icon, contentDescription = it.label)
            })
        }
    }
}


data class BottomItem(val router: String, val label: String, val icon: ImageVector)